package  com.template.controller;



import com.template.common.ServerResponse;
import com.template.model.User;
import com.template.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


/**
 * Title:  UserController
 * Description: 请填写描述信息
 * @author   yls
 * @created  2020年06月10日 11:19:45 星期三
 */
@RestController
@RequestMapping(value = "/user", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 详情
     * @param id
     * @return
     */
    @GetMapping(value = "/detail")
    public ServerResponse detail(@RequestParam(value = "id",required = true) String id){
        return   userService.detail(id);
    }


    /**
     * 列表
     * @return
     */
    @GetMapping(value = "/list")
    public ServerResponse list(){
        return  userService.list();
    }


      /* 列表-分页
     * @param request
     * @param pageNumber 当前页
     * @param pageSize   每页显示记录数
     * @return
     */
    @GetMapping(value = "/pageList")
    public ServerResponse pageList(@RequestParam(value = "pageNumber",required = false,defaultValue = "1") Integer pageNumber,
                                    @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize,
                                    HttpServletRequest request){
        return  userService.pageList(pageNumber,pageSize);
    }



    /**
     * 新增操作
     * @param request
     * @param
     * @return
     */
    @PostMapping(value = "/save")
    public ServerResponse save(User  user, HttpServletRequest request){
       return   userService.save(user);
    }





    /**
     * 更新操作
     * @param request
     * @return
     */
    @PostMapping(value = "/update")
    public ServerResponse  update(User  user, HttpServletRequest request){
        return   userService.update(user);
    }



    /**
     * 删除操作
     * @return
     */
    @PostMapping(value = "/delete")
    public ServerResponse deleteById(@RequestParam(value = "id",required = true) String id){
        return   userService.deleteById(id);
    }


}
